package com.bml.architect.spring;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-rabbitmq-productor.xml")
public class ProductorTest {

    @Autowired
    //1.注入 RabbitTemplate
    private RabbitTemplate rabbitTemplate;

    @Test
    public void testSimple(){
        rabbitTemplate.convertAndSend("spring_simple_q","你好，spring rabbitmq");
    }

    @Test
    public void testFanout(){
        rabbitTemplate.convertAndSend("spring_fanout_exchange","","spring facout....");
    }

    @Test
    public void testDirect(){
        //2.发送消息

        rabbitTemplate.convertAndSend("spring_direct_exchange","abc123","spring Direct....");
    }

    /**
     * 发送topic消息
     */
    @Test
    public void testTopics(){
        //2.发送消息

        rabbitTemplate.convertAndSend("spring_topic_exchange","b1.2021","b1 topic spring test ");
        rabbitTemplate.convertAndSend("spring_topic_exchange","b2.2021","b2 topic spring test ");
        rabbitTemplate.convertAndSend("spring_topic_exchange","b3.xxx.xxx.ttt.2021","b3 topic spring test ");
    }
}
